package com.demo.yuanli.HashMap;

import java.util.HashMap;
import java.util.Iterator;

/** HashMap 原理测试
 * @author LeeXyan
 * @Date 2018/3/8 11:41
 **/
public class HashMapStructure {

    public static void main(String[] args) {

        Country india=new Country("India",1000);
        Country japan=new Country("Japan",10000);

        Country france=new Country("France",2000);
        Country russia=new Country("Russia",20000);

        HashMap<Country,String> countryCapitalMap=new HashMap<Country,String>();
        countryCapitalMap.put(india,"Delhi");
        countryCapitalMap.put(japan,"Tokyo");
        countryCapitalMap.put(france,"Paris");
        countryCapitalMap.put(russia,"Moscow");

        Iterator<Country> countryCapitalIter=countryCapitalMap.keySet().iterator();//put debug point at this line
        while(countryCapitalIter.hasNext())
        {
            Country countryObj=countryCapitalIter.next();
            String capital=countryCapitalMap.get(countryObj);
            System.out.println(countryObj.getName()+"----"+capital);
        }

        //java 8 遍历map
       countryCapitalMap.entrySet().forEach(countryStringEntry -> System.out.println("key:"+countryStringEntry.getKey().name+","+"values:"+countryStringEntry.getValue()));
    }
}
